package com.ruoyi.web.controller.business.customer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.base.PageParam;
import com.ruoyi.business.customer.domain.dto.JbFollowupEvaluationDto;
import com.ruoyi.business.sundry.domain.JbEvaluationExample;
import com.ruoyi.business.sundry.service.JbEvaluationExampleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.bouncycastle.jcajce.provider.symmetric.AES;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.customer.domain.JbFollowupEvaluation;
import com.ruoyi.business.customer.service.JbFollowupEvaluationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 跟进记录评价 Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Api("跟进记录评价")
@RestController
@RequestMapping("/followup_evaluation")
public class JbFollowupEvaluationController extends BaseController
{
    @Autowired
    private JbFollowupEvaluationService service;
    @Autowired
    private JbEvaluationExampleService evaluationExampleService;

    /**
     * 查询跟进记录评价列表
     */
    @ApiOperation("查询跟进记录评价列表")
    @PreAuthorize("@ss.hasPermi('followup_evaluation:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageParam page, JbFollowupEvaluation jbFollowupEvaluation)
    {
        LambdaQueryWrapper<JbFollowupEvaluation> select = new LambdaQueryWrapper<>();
        IPage<JbFollowupEvaluation> iPage = service.page(page.b(), select);
        return getDataTable(iPage.getRecords());
    }

    /**
     * 导出跟进记录评价列表
     */
    @ApiOperation("导出跟进记录评价列表")
    @PreAuthorize("@ss.hasPermi('followup_evaluation:export')")
    @Log(title = "跟进记录评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageParam page, JbFollowupEvaluation jbFollowupEvaluation)
    {
        LambdaQueryWrapper<JbFollowupEvaluation> select = new LambdaQueryWrapper<>();
        IPage<JbFollowupEvaluation> iPage = service.page(page.b(), select);

        List<JbFollowupEvaluation> list = iPage.getRecords();
        ExcelUtil<JbFollowupEvaluation> util = new ExcelUtil<JbFollowupEvaluation>(JbFollowupEvaluation.class);
        util.exportExcel(response, list, "跟进记录评价数据");
    }

    /**
     * 获取跟进记录评价详细信息
     */
    @ApiOperation("获取跟进记录评价详细信息")
    @PreAuthorize("@ss.hasPermi('followup_evaluation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.getById(id));
    }

    /**
     * 新增跟进记录评价
     */
    @ApiOperation("新增跟进记录评价")
    @PreAuthorize("@ss.hasPermi('followup_evaluation:add')")
    @Log(title = "跟进记录评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JbFollowupEvaluationDto jbFollowupEvaluationDto)
    {
        return toAjax(service.saveInfo(jbFollowupEvaluationDto));
    }

    /**
     * 修改跟进记录评价
     */
    @ApiOperation("修改跟进记录评价")
    @PreAuthorize("@ss.hasPermi('followup_evaluation:edit')")
    @Log(title = "跟进记录评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbFollowupEvaluation jbFollowupEvaluation)
    {
        return toAjax(service.updateById(jbFollowupEvaluation));
    }

    /**
     * 删除跟进记录评价
     */
    @ApiOperation("删除跟进记录评价")
    @PreAuthorize("@ss.hasPermi('followup_evaluation:remove')")
    @Log(title = "跟进记录评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        boolean b = service.removeByIds(Arrays.asList(ids));
        if (b){
            evaluationExampleService.remove(Wrappers.lambdaQuery(JbEvaluationExample.class).in(JbEvaluationExample::getEvaluationId,ids));
        }
        return toAjax(b);
    }
}
